﻿using System;
using System.Windows.Forms;
using agsXMPP;
using Lapd.Common.CustomStanzas;
using agsXMPP.protocol.client;

namespace Lapd.PoC
{
    public partial class JoinGroup : Form
    {
        private XmppClientConnection xmppClientConnection;

        public JoinGroup(XmppClientConnection xmppClientConnection)
        {
            InitializeComponent();

            this.xmppClientConnection = xmppClientConnection;
        }

        private void mitJoin_Click(object sender, EventArgs e)
        {
            // Prepare SddsIq JOIN packet
            Jid jidTo = new Jid(CustomStanzasConstants.JidToPreffixConst + "." + Session.Server);
            Jid jidFrom = new Jid(Session.Jid);
            Join join = new Join(txtGroupName.Text);
            Sdds sdds = new Sdds(join);
            SddsIq sddsIq = new SddsIq(sdds) {Type = IqType.set, To = jidTo, From = jidFrom};

            xmppClientConnection.Send(sddsIq);

            this.Close();
        }

        private void mitCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}